package com.mvc.controller;

import com.alibaba.fastjson.JSON;
import com.mvc.entity.User;
import com.mvc.model.Result;
import com.mvc.service.CommodityGradeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName CommodityGradeController
 * @Description TODO
 * @Author king
 * @Date 2021/12/2 19:21
 * @Version 1.0
 **/
@Controller
@RequestMapping(value = "/pingjia", produces = "text/html;charset=UTF-8")
public class CommodityGradeController {
    @Autowired
    private CommodityGradeService commodityGradeService;
    @RequestMapping(value = "/list.do")
    @ResponseBody
    public String listSearch(@RequestParam Integer page, @RequestParam Integer limit,
                             @RequestParam(required = false) Integer shop_id, @RequestParam(required = false) String uname){
        Integer startRow = (page - 1) * limit;
        List<User> list = commodityGradeService.listSearch(startRow, limit,shop_id,uname);
        Integer count = commodityGradeService.getCount(shop_id, uname);
        Result result = new Result();
        result.setCode(0);
        result.setData(list);
        result.setCount(count);
        String json = JSON.toJSONString(result);
        return json;
    }
}
